const Admin = require('./models/admin')
const User = require('./models/user')
const Driver = require('./models/driver')
const Order = require('./models/order')

router.post("/userlogin", async (ctx, next) => {
	await next()
	let utel = ctx.request.body["utel"]
	let upassword = ctx.request.body["upassword"]
	if (utel == undefined || utel == '') {
		ctx.body = {msg:"用户电话不能为空"}
		return
	}
	if (upassword == undefined || upassword == '') {
		ctx.body = {msg:"用户密码不能为空"}
		return
	}
	// 去MongoDB判断改用户是否存在
	let result = await User.find({
		'utel': utel,
		'upassword': upassword
	}).then(res => {
		if (res.length > 0) {
			return {msg:"用户登录成功",err:""}
		} else {
			return {msg:"用户登录失败",err:""}
		}
	}).catch(err => {
		return {msg:"用户登录失败",err:err}
	})

	ctx.body = result

})